package sk.hackcraft.util.simulation.statistics;

public class TimeStatistics
{
	private double lastUpdateTime;
	private long cumulatedValue;
	private int lastStatus;

	public TimeStatistics()
	{
		this.lastUpdateTime = 0;
		this.cumulatedValue = 0;
		this.lastStatus = 0;
	}
	
	public void addValue(double time, int status)
	{
		this.cumulatedValue += (time-lastUpdateTime)*lastStatus;
        this.lastUpdateTime = time;
		this.lastStatus = status;
	}
	
	public void addRelativeValue(double time, int relativeValue)
	{
		addValue(time, lastStatus + relativeValue);
	}
	
	public double getAverage()
	{
		if(this.lastUpdateTime == 0)
		{
			return 0;
		}
		
		return this.cumulatedValue / this.lastUpdateTime;
	}
	
	public void clear()
	{
		this.lastUpdateTime = 0;
		this.cumulatedValue = 0;
	}
}
